package xuegao.study.mall.admin.controller;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import xuegao.study.mall.admin.feign.OmsOrderClient;
import xuegao.study.mall.common.dto.*;
import xuegao.study.mall.common.api.CommonPage;
import xuegao.study.mall.common.api.CommonResult;
import xuegao.study.mall.common.model.oms.OmsOrder;

import java.util.List;

/**
 * 订单管理
 */
@RestController
@RequestMapping("/order")
public class OmsOrderController {

    @Autowired
    private OmsOrderClient omsOrderClient;

    @ApiOperation("查询订单")
    @GetMapping("/list")
    public CommonResult<CommonPage<OmsOrder>> list(OmsOrderQueryParam queryParam,
                                                   @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                                                   @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        List<OmsOrder> list = omsOrderClient.list(queryParam, pageSize, pageNum);
        return CommonResult.success(CommonPage.restPage(list));
    }

    @ApiOperation("获取订单详情")
    @GetMapping(value = "/{id}")
    public CommonResult<OmsOrderDetail> detail(@PathVariable Long id) {
        OmsOrderDetail detail = omsOrderClient.detail(id);
        return CommonResult.success(detail);
    }

    @ApiOperation("批量发货")
    @PostMapping("/update/delivery")
    public CommonResult delivery(@RequestBody List<OmsOrderDeliveryParam> deliveryParamList) {
        return omsOrderClient.delivery(deliveryParamList);
    }

    @ApiOperation("批量关闭订单")
    @PostMapping(value = "/update/close")
    public CommonResult close(@RequestParam("ids") List<Long> ids, @RequestParam String note) {
        return omsOrderClient.close(ids, note);
    }

    @ApiOperation("批量删除订单")
    @PostMapping(value = "/delete")
    public CommonResult delete(@RequestParam("ids") List<Long> ids) {
        return omsOrderClient.delete(ids);
    }

    @ApiOperation("修改收货人信息")
    @PostMapping(value = "/update/receiverInfo")
    public CommonResult updateReceiverInfo(@RequestBody OmsReceiverInfoParam param) {
        return omsOrderClient.updateReceiverInfo(param);
    }

    @ApiOperation("修改订单费用信息")
    @PostMapping(value = "/update/moneyInfo")
    public CommonResult updateMoneyInfo(@RequestBody OmsMoneyInfoParam param) {
        return omsOrderClient.updateMoneyInfo(param);
    }

    @ApiOperation("备注订单")
    @PostMapping(value = "/update/note")
    public CommonResult updateNote(@RequestParam("id") Long id,
                                   @RequestParam("note") String note,
                                   @RequestParam("status") Integer status) {
        return omsOrderClient.updateNote(id, note, status);
    }
}
